<% web_form_shared_secret= Spree::BrontoConfiguration.account[current_store.code]['web_form_shared_secret']
   site_id= Spree::BrontoConfiguration.account[current_store.code]['site_id']
   preference_form_id= Spree::BrontoConfiguration.account[current_store.code]['preference_form_id']

   user_hash =OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), web_form_shared_secret, site_id + preference_form_id + @user.email)

   form_url= "http://app.bronto.com/public/webform/lookup/#{preference_form_id}/#{site_id}/manpref/#{@user.email}/#{user_hash}"
%>

<div id="account" class="content_tabs_wrapper" style="padding-top: 50px;">
  <div id="content_tabs" class="ui-tabs ui-widget ui-widget-content" style="display:block;border:none;height:auto !important;">
    <ul class="ui-tabs-nav ui-helper-reset ui-helper-clearfix" role="tablist">

      <li role="tab" tabindex="1" aria-controls="profile-tab" aria-labelledby="ui-id-1" aria-selected="false" text-align="center">
        <a href="/account#profile" class="ui-tabs-anchor" role="presentation"><img src="/assets/nwb/profile.png" height="50px" align="center" padding-top="20px"><div style="text-align: center;padding-top: 10px;">Profile</div></a>
      </li>

      <li role="tab" tabindex="2" aria-controls="profile-tab" aria-labelledby="ui-id-2" aria-selected="false">
        <a href="/account#orders" class="ui-tabs-anchor" role="presentation"><img src="/assets/nwb/orders.png" height="50px" align="center"><div style="text-align: center;padding-top: 10px;">Orders</div></a>
      </li>

      <li role="tab" tabindex="3" aria-controls="autodelivery-tab" aria-labelledby="ui-id-3" aria-selected="false">
        <a href="/account#autodelivery" class="ui-tabs-anchor" role="presentation"><img src="/assets/nwb/autodelivery.png" height="50px" align="center"><div style="text-align: center;padding-top: 10px;">Auto Delivery</div></a>
      </li>
      <li role="tab" tabindex="4" aria-controls="emailpreferences-tab" aria-labelledby="ui-id-4" aria-selected="false" class="active">
        <a href="#" class="ui-tabs-anchor" role="presentation"><img src="/assets/nwb/mail.png" height="50px" align="center"><div style="text-align: center;padding-top: 10px;">Email Preferences</div></a>
      </li>
    </ul>
  </div>
</div>

<div class="bronto">

  <%
     def get_html_content(requested_url)
       url = URI.parse(requested_url)
       full_path = (url.query.blank?) ? url.path : "#{url.path}?#{url.query}"
       the_request = Net::HTTP::Get.new(full_path)

       #the_request.use_ssl = (url.scheme == "https")

       the_response = Net::HTTP.start(url.host, url.port) { |http|
         http.request(the_request)
       }

       return "<p>Sorry not available at this moment</p>" if !the_response || the_response.code != "200"
       return the_response.body
     end
  %>
  <%= raw(get_html_content(form_url)) %>

</div>
